<!-- 组件名: index -->
<!-- 创建日期: 2023/12/25 -->
<!-- 编写者: Adil -->

<template>
  <el-upload
    class="avatar-uploader"
    action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
    :show-file-list="false"
    :auto-upload="false"
    :on-change="handleChange"
  >
    <img
      v-if="avatar"
      :src="uploadAvatar"
      class="avatar" />
    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  </el-upload>
</template>

<script>
export default {
  name: "index",
  components: {},
  props: {
    avatar: {
      type: String
    }
  },
  data() {
    return {};
  },
  // 计算属性
  computed: {
    uploadAvatar() {
      return this.avatar.includes("blob")?this.avatar:'http://localhost:3000'+this.avatar
    }
  },
  methods: {
    handleChange(file) {
      this.$emit('adilChange', file.raw)
    }
  }
}
</script>

<style lang="scss" scoped>
.avatar-uploader {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
